﻿using AutoMapper;
using System.Reflection;
using Zws.Common.ScanTool;

namespace Zws.AutoMapper
{
    public abstract class ProfileMark : Profile
    {
        public ProfileMark()
        {
            //根据特性添加automapper，复杂的自己手动添加
            var types = ScanHelper.ScanSpecialPublicClassByAssemblys(type => type.GetCustomAttribute<CreateMapperAttribute>() != null);
            foreach (var type in types)
            {
                var mapAttr = type.GetCustomAttribute<CreateMapperAttribute>();
                //如果设置为true，则配置跟指定类型的反向映射
                if (mapAttr.IsReverseMap)
                    CreateMap(mapAttr.MapType, type);
                else
                    CreateMap(type, mapAttr.MapType);
            }
        }
    }
}
